VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CFileOutputHandler"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Option Explicit

Public Append As Boolean

Private mvarFileName As String
Private hFile As Integer

Private Const fihNoCurrentFile As Long = -1
Public Sub CloseFile()

  If hFile <> fihNoCurrentFile Then
    Close #hFile
    hFile = fihNoCurrentFile
  End If

End Sub

Public Property Get IsOpen() As Boolean
Attribute IsOpen.VB_UserMemId = 0
Attribute IsOpen.VB_MemberFlags = "200"

  IsOpen = (hFile <> fihNoCurrentFile)

End Property

Public Function WriteFile(FileContents As String) As Boolean

  On Error GoTo WriteFileError

  If hFile <> fihNoCurrentFile Then
    CloseFile
    If OpenFile Then
      Print #hFile, FileContents;
      CloseFile
    End If
  End If

  WriteFile = True
  Exit Function
  
WriteFileError:
  MsgBox Err.Description, vbCritical, "Write File"

End Function

Public Function OpenFile(Optional FileName As String = "") As Boolean

  On Error GoTo OpenFileError

  If FileName <> "" Then
    mvarFileName = FileName
  End If

  CloseFile
  
  hFile = FreeFile
  
  If Append Then
    Open mvarFileName For Append As #hFile
  Else
    Open mvarFileName For Output As #hFile
  End If
  
  OpenFile = True
  Exit Function
  
OpenFileError:
  MsgBox Err.Description, vbCritical, "Open File"

End Function
Public Function WriteBytes(Bytes() As Byte) As Boolean

  Dim sTemp As String

  On Error GoTo WriteBytesError

  LSet sTemp = Bytes()

  If hFile <> fihNoCurrentFile Then
    Print #hFile, sTemp;
  End If

  WriteBytes = True
  Exit Function
  
WriteBytesError:
  MsgBox Err.Description, vbCritical, "WriteBytes"

End Function

Public Function WriteChars(WriteString As String) As Boolean

  On Error GoTo WriteCharsError

  If hFile <> fihNoCurrentFile Then
    Print #hFile, WriteString;
  End If

  WriteChars = True
  Exit Function
  
WriteCharsError:
  MsgBox Err.Description, vbCritical, "WriteChars"

End Function

Public Function WriteLine(Line As String) As Boolean

  On Error GoTo WriteLineError

  If hFile <> fihNoCurrentFile Then
    Print #hFile, Line
  End If

  WriteLine = True
  Exit Function
  
WriteLineError:
  MsgBox Err.Description, vbCritical, "Write Line"
  
End Function


Private Sub Class_Initialize()

  hFile = fihNoCurrentFile
  mvarFileName = ""
    
End Sub



Public Property Get FileName() As String

  FileName = mvarFileName

End Property

Public Property Let FileName(ByVal vNewValue As String)
  
  CloseFile
  
  mvarFileName = vNewValue
  
End Property

Private Sub Class_Terminate()

  CloseFile
  
End Sub


